//
//  SYS_HelpModel.m
//  System_App
//
//  Created by czy001 on 2017/11/27.
//  Copyright © 2017年 czy001. All rights reserved.
//

#import "SYS_HelpModel.h"

@implementation SYS_HelpModel

+ (CGRect)caculateRectFromString:(NSString *)str withFontOfSize:(float)f withWidth:(float)width
{
    CGRect textRect = [str boundingRectWithSize:CGSizeMake(width, MAXFLOAT) options:NSStringDrawingUsesLineFragmentOrigin | NSStringDrawingUsesFontLeading attributes:@{NSFontAttributeName : [UIFont systemFontOfSize:f]} context:nil];
    return textRect;
}

/*手机号码验证 MODIFIED BY HELENSONG*/
+(BOOL) isValidateMobile:(NSString *)mobile
{
    //手机号以13， 15，18,17开头，八个 \d 数字字符
    NSString *phoneRegex = @"^((13[0-9])|(15[0-9])|(14[57])|(17[0-9])|(18[0-9]))\\d{8}$";
    NSPredicate *phoneTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",phoneRegex];
    //    NSLog(@"phoneTest is %@",phoneTest);
    return [phoneTest evaluateWithObject:mobile];
    
}

//计算当前标签显示高度
+ (float)caculateTagHeight:(NSString *)str withWidth:(float)width
{
    NSArray *array=[str componentsSeparatedByString:@","];
    float height=10+20*(int)(70*[array count]/width+1);
    return height;
}

//利用正则表达式验证
+(BOOL)isValidateEmail:(NSString *)email {
    NSString *emailRegex = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
    NSPredicate *emailTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", emailRegex];
    return [emailTest evaluateWithObject:email];
}


//判断是否为double：
+ (BOOL)isPureDouble:(NSString*)string{
    
    NSScanner* scan = [NSScanner scannerWithString:string];
    double val;
    return[scan scanDouble:&val] && [scan isAtEnd];
}
////根据字体大小，行间距,宽度来判断label高度
//+ (float)caculateLabelHeight:(NSString *)str withFontLimit:(float)font withLineSpace:(float)space withWidth:(float)width
//{
//    ExtendLabel *label=[[ExtendLabel alloc] init];
//    //        label1.text=[arr objectAtIndex:0];
//    label.lineSpace=space;
//    label.numberOfLines=0;
//    label.backgroundColor=[UIColor redColor];
//    label.font=[UIFont systemFontOfSize:font];
//
//    label.sd_layout
//    .widthIs(width)
//    .autoHeightRatio(0);
//    label.isAttributedContent=YES;
//
//    label.text=str;
//    //    NSLog(@"frame0------%@",[NSValue valueWithCGRect:label.frame]);
//
//    return label.frame.size.height;
//}

//nsdate转nsstring
+ (NSString *)stringFromDate:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息。
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd"];
    
    NSString *destDateString = [dateFormatter stringFromDate:date];
    
    return destDateString;
    
}

//时间戳转nsdate
+ (NSDate *)convertTimeToDate:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    return date;
}

+ (NSString *)stringFromDateWithHours:(NSDate *)date{
    
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //zzz表示时区，zzz可以删除，这样返回的日期字符将不包含时区信息。
    
    [dateFormatter setDateFormat:@"yyyy-MM-dd hh:mm"];
    
    NSString *destDateString = [dateFormatter stringFromDate:date];
    
    return destDateString;
    
}

//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTime:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy/MM/dd HH:mm:ss"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTime1:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy/MM/dd HH:mm"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTime333:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTime11:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}


//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTimeYear:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTimeYearPoint:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间
+ (NSString *)timestampTransformedIntoStandardTimeYear1:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"MM-dd"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间   年 时 分
+ (NSString *)timestampTransformedIntoStandardTimeHours:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间   年 时 分
+ (NSString *)timestampTransformedIntoStandardTimeHours1:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"HH:mm"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}

//显示标准时间    时
+ (NSString *)timestampTransformedIntoStandardTimeHours222:(long long int)time
{
    NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"HH"];
    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time];
    
    NSString *dateString=[formatter stringFromDate:date];
    
    return dateString;
}



//显示时间差 如几天前
+ (NSString *)timestampTransformedIntervalTime:(long long int)time
{
    //    NSDate *dateNow=[NSDate date];
    //    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    //
    //    NSInteger interval = [zone secondsFromGMTForDate:dateNow];
    //
    //    NSDate *date=[NSDate dateWithTimeIntervalSince1970:time-interval];
    
    NSDate *date=[self convertTimeToDate:time];
    return [self computeTimeInterval:date];
}


+ (NSString *)computeTimeInterval:(NSDate *)date
{
    NSDate *now = [NSDate date];
    //    NSTimeZone *zone = [NSTimeZone systemTimeZone];
    //
    //    NSInteger interval = [zone secondsFromGMTForDate:now];
    //
    //    NSDate *localeDate = [now dateByAddingTimeInterval:interval];
    
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute | NSCalendarUnitSecond;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:now];
    
    //    int year =(int) [dateComponent year];
    //    int month = (int) [dateComponent month];
    //    int day = (int) [dateComponent day];
    //    int hour = (int) [dateComponent hour];
    //    int minute = (int) [dateComponent minute];
    //    int second = (int) [dateComponent second];
    
    
    NSTimeInterval timeInterval = [date timeIntervalSinceNow];
    timeInterval = -timeInterval;
    long temp = 0;
    NSString *result;
    if (timeInterval < 60) {//1分钟内
        result = [NSString stringWithFormat:@"%d秒前", (int)timeInterval];
    }
    else if((temp = timeInterval/60) < 60){//10分钟到1小时
        result = [NSString stringWithFormat:@"%d分前", (int)temp];
    }else if((temp = temp/60) < 24){
        result = [NSString stringWithFormat:@"%d小时前", (int)temp];
    }
    else{
        NSDateFormatter* formatter = [[NSDateFormatter alloc] init];
        [formatter setDateStyle:NSDateFormatterMediumStyle];
        [formatter setTimeStyle:NSDateFormatterShortStyle];
        [formatter setDateFormat:@"yyyy-MM-dd"];
        
        result=[formatter stringFromDate:date];
    }
    
    NSLog(@"result----%@",result);
    return result;
}

//字符串转时间戳
+ (NSString *)convertToTime:(NSString *)time
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY/MM/dd HH:mm"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    //例如你在国内发布信息,用户在国外的另一个时区,你想让用户看到正确的发布时间就得注意时区设置,时间的换算.
    //例如你发布的时间为2010-01-26 17:40:50,那么在英国爱尔兰那边用户看到的时间应该是多少呢?
    //他们与我们有7个小时的时差,所以他们那还没到这个时间呢...那就是把未来的事做了
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    
    NSDate* date = [formatter dateFromString:time]; //------------将字符串按formatter转成nsdate
    NSString *timeSp = [NSString stringWithFormat:@"%ld000", (long)[date timeIntervalSince1970]];
    return timeSp;
}

//字符串转时间戳
+ (NSString *)convertToTimeOnlineOrder:(NSString *)time
{
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    [formatter setDateStyle:NSDateFormatterMediumStyle];
    [formatter setTimeStyle:NSDateFormatterShortStyle];
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm"]; // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    //设置时区,这个对于时间的处理有时很重要
    //例如你在国内发布信息,用户在国外的另一个时区,你想让用户看到正确的发布时间就得注意时区设置,时间的换算.
    //例如你发布的时间为2010-01-26 17:40:50,那么在英国爱尔兰那边用户看到的时间应该是多少呢?
    //他们与我们有7个小时的时差,所以他们那还没到这个时间呢...那就是把未来的事做了
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [formatter setTimeZone:timeZone];
    
    NSDate* date = [formatter dateFromString:time]; //------------将字符串按formatter转成nsdate
    NSString *timeSp = [NSString stringWithFormat:@"%ld000", (long)[date timeIntervalSince1970]];
    return timeSp;
}


//根据颜色制作image
+ (UIImage *)createImageWithColor:(UIColor *)color
{
    UIGraphicsBeginImageContext(CGSizeMake(100, 100));
    CGContextRef context=UIGraphicsGetCurrentContext();
    CGContextAddRect(context, CGRectMake(0, 0, 100, 100));
    CGContextSetFillColorWithColor(context, color.CGColor);
    
    CGContextFillPath(context);
    
    UIImage *image=UIGraphicsGetImageFromCurrentImageContext();
    return image;
}

+ (NSString *)caculateTheAgeWithTime:(long long int)time
{
    NSDate *birth = [NSDate dateWithTimeIntervalSince1970:time/1000];
    NSCalendar *calendar = [NSCalendar currentCalendar];
    NSUInteger unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay;
    NSDateComponents *dateComponent = [calendar components:unitFlags fromDate:birth];
    NSInteger birthYear = [dateComponent year];
    
    dateComponent = [calendar components:unitFlags fromDate:[NSDate date]];
    NSInteger nowYear = [dateComponent year];
    
    NSString *age=[NSString stringWithFormat:@"%i岁",(int)(nowYear-birthYear)];
    return age;
}

////获取当前时间的年月日和周几
//+ (DSTimeModel *)getCurrentTimeInfo:(NSDate *)date
//{
//    DSTimeModel *model=[[DSTimeModel alloc] init];
//    
//    NSCalendar*calendar = [NSCalendar currentCalendar];
//    NSDateComponents*comps;
//    // 年月日获得
//    
//    comps =[calendar components:(NSCalendarUnitYear | NSCalendarUnitMonth |NSCalendarUnitDay |NSCalendarUnitHour | NSCalendarUnitMinute |NSCalendarUnitSecond)
//                       fromDate:date];
//    
//    NSInteger year = [comps year];
//    NSInteger month = [comps month];
//    NSInteger day = [comps day];
//    NSInteger hour = [comps hour];
//    NSInteger minute = [comps minute];
//    NSInteger second = [comps second];
//    
//    model.year=[NSString stringWithFormat:@"%i",(int)year];
//    if (month<10) {
//        model.month=[NSString stringWithFormat:@"0%i",(int)month];
//    }
//    else
//    {
//        model.month=[NSString stringWithFormat:@"%i",(int)month];
//    }
//    
//    if (day<10) {
//        model.day=[NSString stringWithFormat:@"0%i",(int)day];
//    }
//    else
//    {
//        model.day=[NSString stringWithFormat:@"%i",(int)day];
//    }
//    
//    if (hour<10) {
//        model.hour=[NSString stringWithFormat:@"0%i",(int)hour];
//    }
//    else
//    {
//        model.hour=[NSString stringWithFormat:@"%i",(int)hour];
//    }
//    
//    if (minute<10) {
//        model.minute=[NSString stringWithFormat:@"0%i",(int)minute];
//    }
//    else
//    {
//        model.minute=[NSString stringWithFormat:@"%i",(int)minute];
//    }
//    
//    if (second<10) {
//        model.second=[NSString stringWithFormat:@"0%i",(int)second];
//    }
//    else
//    {
//        model.second=[NSString stringWithFormat:@"%i",(int)second];
//    }
//    
//    // 周几和星期几获得
//    
//    comps =[calendar components:(NSCalendarUnitWeekday | NSCalendarUnitWeekdayOrdinal)
//                       fromDate:date];
//    
//    NSInteger weekday = [comps weekday];
//    switch (weekday) {
//        case 1:
//            model.weekDay=@"星期天";
//            break;
//            
//        case 2:
//            model.weekDay=@"星期一";
//            break;
//            
//        case 3:
//            model.weekDay=@"星期二";
//            break;
//            
//        case 4:
//            model.weekDay=@"星期三";
//            break;
//            
//        case 5:
//            model.weekDay=@"星期四";
//            break;
//            
//        case 6:
//            model.weekDay=@"星期五";
//            break;
//            
//        case 7:
//            model.weekDay=@"星期六";
//            break;
//            
//        default:
//            break;
//    }
//    return model;
//}


+(BOOL)checkNumber:(NSString *)number{
    
    //验证输入的固话中不带 "-"符号
    
    //    (13[0-9])|(15[0-9])|(14[57])|(17[0-9])|(18[0-9])
    
    //验证输入的固话中带 "-"符号
    //验证输入的固话中不带 "-"符号
    
    NSString * strNum = @"^(0[0-9]{2,3})?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\\d{8}$)";
    
    //验证输入的固话中带 "-"符号
    
    NSString * strNum1 = @"^(0[0-9]{2,3}-)?([2-9][0-9]{6,7})+(-[0-9]{1,4})?$|(^(13[0-9]|15[0|3|6|7|8|9]|18[8|9])\\d{8}$)";
    
    NSPredicate *checktest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", strNum];
    NSPredicate *checktest1 = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", strNum1];
    
    return [checktest evaluateWithObject:number] || [checktest1 evaluateWithObject:number];
    
}


//判断字符长度
+  (int)convertToInt:(NSString*)strtemp {
    
    int strlength = 0;
    char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
    for (int i=0 ; i<[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++) {
        if (*p) {
            p++;
            strlength++;
        }
        else {
            p++;
        }
    }
    return strlength;
}


//将yyyy-MM-dd HH:mm:ss格式时间转换成时间戳
+(long )changeTimeToTimeSp:(NSString *)timeStr{
    long time;
    NSDateFormatter *format=[[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy-MM-dd"];
    NSDate *fromdate=[format dateFromString:timeStr];
    time= (long)[fromdate timeIntervalSince1970];
    return time;
}

//将yyyy格式时间转换成时间戳
+(long )changeTimeToTimeSp1:(NSString *)timeStr{
    long time;
    NSDateFormatter *format=[[NSDateFormatter alloc] init];
    [format setDateFormat:@"yyyy"];
    NSDate *fromdate=[format dateFromString:timeStr];
    time= (long)[fromdate timeIntervalSince1970];
    return time;
}



//规避null数据
+ (NSString *)checkData:(id)str
{
    if ([str isKindOfClass:[NSNull class]] || str == nil) {
        str=@" ";
        return str;
    }
    else if ([str isKindOfClass:[NSString class]])
    {
        NSString *s=(NSString *)str;
        if (s.length == 0) {
            return @" ";
        }
        else
        {
            return s;
        }
    }
    else if ([str isKindOfClass:[NSNumber class]])
    {
        NSString *s=[str stringValue];
        if (s.length == 0) {
            return @" ";
        }
        else
        {
            return s;
        }
    }
    return nil;
}

+(BOOL)checkPassWord:(NSString *)pwd
{
    //6-20位数字和字母组成
    NSString *regex = @"^(?![0-9]+$)(?![a-zA-Z]+$)[0-9A-Za-z]{6,20}$";
    NSPredicate *   pred = [NSPredicate predicateWithFormat:@"SELF MATCHES %@", regex];
    if ([pred evaluateWithObject:pwd]) {
        return YES ;
    }else
        return NO;
}

//利用正则表达式验证车牌号
+(BOOL)isValidateCarNumber:(NSString *)number {
    NSString *carRegex = @"^[A-Z_0-9]{5}$";
    NSPredicate *carTest = [NSPredicate predicateWithFormat:@"SELF MATCHES %@",carRegex];
    return [carTest evaluateWithObject:number];
}

+ (NSString *)getChineseStringWithString:(NSString *)string
{
    //(unicode中文编码范围是0x4e00~0x9fa5)
    for (int i = 0; i < string.length; i++) {
        int utfCode = 0;
        void *buffer = &utfCode;
        NSRange range = NSMakeRange(i, 1);
        
        BOOL b = [string getBytes:buffer maxLength:2 usedLength:NULL encoding:NSUTF16LittleEndianStringEncoding options:NSStringEncodingConversionExternalRepresentation range:range remainingRange:NULL];
        
        if (b && (utfCode >= 0x4e00 && utfCode <= 0x9fa5)) {
            return [string substringFromIndex:i];
        }
    }
    return nil;
}

/*
 * @brief 把格式化的JSON格式的字符串转换成字典
 * jsonString JSON格式的字符串
 * @return 返回字典
 */
+ (NSDictionary *)dictionaryWithJsonString:(NSString *)jsonString {
    if (jsonString == nil) {
        return nil;
    }
    
    NSData *jsonData = [jsonString dataUsingEncoding:NSUTF8StringEncoding];
    NSError *err;
    NSDictionary *dic = [NSJSONSerialization JSONObjectWithData:jsonData
                                                        options:NSJSONReadingMutableContainers
                                                          error:&err];
    if(err) {
        NSLog(@"json解析失败：%@",err);
        return nil;
    }
    return dic;
}

+ (NSString*)weekdayStringFromDate:(NSDate*)inputDate {
    
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"周日", @"周一", @"周二", @"周三", @"周四", @"周五", @"周六", nil];
    
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
    
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    
    [calendar setTimeZone: timeZone];
    
    NSCalendarUnit calendarUnit = NSWeekdayCalendarUnit;
    
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:inputDate];
    
    return [weekdays objectAtIndex:theComponents.weekday];
    
}

+(NSString *) picConversionOriginal:(NSString *)picUrl andPicRect:(CGRect)frame
{
    if (picUrl.length == 0){
        return nil;
    }
    NSMutableString *picU=[NSMutableString stringWithString:picUrl];
    
    NSInteger scale;
    if (SCREENHEIGHT<=667) {
        scale=2;//6P以下
    }else if(SCREENHEIGHT==736){
        
        scale=3;//6P
    }
    NSString *pid=FORMAT(@"-%.f|%.f",frame.size.width*scale,scale*frame.size.height);
    [picU appendString:pid];
    NSString *str1 = [picU stringByAddingPercentEscapesUsingEncoding:
                      NSUTF8StringEncoding];
    
    return str1;
}


//判断内容是否全部为空格 yes 全部为空格 no 不是
+(BOOL) isEmpty1:(NSString *) str {
    
    if(!str) {
        
        return true;
        
    }else {
        
        
        //A character set containing only the whitespace characters space (U+0020) and tab (U+0009) and the newline and next line characters (U+000A–U+000D,U+0085).
        
        
        NSCharacterSet *set = [NSCharacterSet whitespaceAndNewlineCharacterSet];
        
        
        //Returns a new string made by removing from both ends of the receiver characters contained in a given character set.
        
        
        NSString *trimedString = [str stringByTrimmingCharactersInSet:set];
        
        
        if([trimedString length] == 0) {
            
            return true;
            
            
        }else {
            
            
            return false;
            
            
        }
    }
}

//计算截止日期到当前时间的间隔
+ (NSString *)caculateIntervalFromNow:(long long int)value
{
    long long int currentTime=[[NSDate date] timeIntervalSince1970];
    if (value/1000<currentTime) {
        return @"已过期";
    }
    else
    {
        long long int interval=value/1000-currentTime;
        return [NSString stringWithFormat:@"%lli天%lli小时",interval/(3600*24),interval%(3600*24)/3600];
    }
    return nil;
}

//解决图片旋转问题
+ (UIImage *)fixOrientation:(UIImage *)aImage {
    
    // No-op if the orientation is already correct
    if (aImage.imageOrientation == UIImageOrientationUp)
        return aImage;
    
    // We need to calculate the proper transformation to make the image upright.
    // We do it in 2 steps: Rotate if Left/Right/Down, and then flip if Mirrored.
    CGAffineTransform transform = CGAffineTransformIdentity;
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationDown:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, aImage.size.height);
            transform = CGAffineTransformRotate(transform, M_PI);
            break;
            
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformRotate(transform, M_PI_2);
            break;
            
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, 0, aImage.size.height);
            transform = CGAffineTransformRotate(transform, -M_PI_2);
            break;
        default:
            break;
    }
    
    switch (aImage.imageOrientation) {
        case UIImageOrientationUpMirrored:
        case UIImageOrientationDownMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.width, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
            
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRightMirrored:
            transform = CGAffineTransformTranslate(transform, aImage.size.height, 0);
            transform = CGAffineTransformScale(transform, -1, 1);
            break;
        default:
            break;
    }
    
    // Now we draw the underlying CGImage into a new context, applying the transform
    // calculated above.
    CGContextRef ctx = CGBitmapContextCreate(NULL, aImage.size.width, aImage.size.height,
                                             CGImageGetBitsPerComponent(aImage.CGImage), 0,
                                             CGImageGetColorSpace(aImage.CGImage),
                                             CGImageGetBitmapInfo(aImage.CGImage));
    CGContextConcatCTM(ctx, transform);
    switch (aImage.imageOrientation) {
        case UIImageOrientationLeft:
        case UIImageOrientationLeftMirrored:
        case UIImageOrientationRight:
        case UIImageOrientationRightMirrored:
            // Grr...
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.height,aImage.size.width), aImage.CGImage);
            break;
            
        default:
            CGContextDrawImage(ctx, CGRectMake(0,0,aImage.size.width,aImage.size.height), aImage.CGImage);
            break;
    }
    
    // And now we just create a new UIImage from the drawing context
    CGImageRef cgimg = CGBitmapContextCreateImage(ctx);
    UIImage *img = [UIImage imageWithCGImage:cgimg];
    CGContextRelease(ctx);
    CGImageRelease(cgimg);
    return img;
    
}


+ (UIButton *)createBackButton{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    backBtn.frame = CGRectMake(15, 10, 11, 22);
    [backBtn setBackgroundImage:WJIMAGE(@"navigation_back.png") forState:UIControlStateNormal];
    return backBtn;
}

//#pragma mark -得到当前时间
+ (NSDate *)CurrentTime{
    NSDateFormatter *formatter=[[NSDateFormatter alloc]init];
    //当前时间格式
    [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *dateTime=[formatter stringFromDate:[NSDate date]];
    NSDate *date = [formatter dateFromString:dateTime];
    
    NSLog(@"---------- currentDate == %@",date);
    return date;
    
}
//#当前时间和后台返回的时间比较方法，返回一个int类型的数据
+ (int)compareCurrentTimeDay:(NSDate *)oneDay withAnotherDay:(NSDate *)anotherDay
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //这个时间格式需要和当前得到时间格式相同才能做比较
    [dateFormatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSString *oneDayStr = [dateFormatter stringFromDate:oneDay];
    NSString *anotherDayStr = [dateFormatter stringFromDate:anotherDay];
    NSDate *dateA = [dateFormatter dateFromString:oneDayStr];
    NSDate *dateB = [dateFormatter dateFromString:anotherDayStr];
    NSComparisonResult result = [dateA compare:dateB];
    NSLog(@"date1 : %@, date2 : %@", oneDay, anotherDay);
    if (result == NSOrderedDescending) {
        //NSLog(@"Date1  is in the future");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"Date1 is in the past");
        return -1;
    }
    //NSLog(@"Both dates are the same");
    return 0;
    
}

//比较两个日期的大小  日期格式为2016-08-14 08：46：20
+ (NSInteger)compareDate:(NSString*)aDate withDate:(NSString*)bDate
{
    NSDateFormatter *dateformater = [[NSDateFormatter alloc] init];
    [dateformater setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
    NSDate *dta = [[NSDate alloc] init];
    NSDate *dtb = [[NSDate alloc] init];
    
    NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:@"Asia/Shanghai"];
    [dateformater setTimeZone:timeZone];
    
    dta = [dateformater dateFromString:aDate];
    dtb = [dateformater dateFromString:bDate];
    NSComparisonResult result = [dta compare:dtb];
    
    if (result == NSOrderedDescending) {
        //NSLog(@"Date1  is in the future");
        return 1;
    }
    else if (result == NSOrderedAscending){
        //NSLog(@"Date1 is in the past");
        return -1;
    }
    //NSLog(@"Both dates are the same");
    return 0;
}

//获取当前的时间
+(NSString*)getCurrentTimes{
    
    NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
    
    // ----------设置你想要的格式,hh与HH的区别:分别表示12小时制,24小时制
    
    [formatter setDateFormat:@"YYYY-MM-dd HH:mm:ss"];
    
    //现在时间,你可以输出来看下是什么格式
    
    NSDate *datenow = [NSDate date];
    
    //----------将nsdate按formatter格式转成nsstring
    
    NSString *currentTimeString = [formatter stringFromDate:datenow];
    
    NSLog(@"currentTimeString =  %@",currentTimeString);
    
    return currentTimeString;
    
}

//*取字符串首字母，返回大写字母*/
+ (NSString *)transformMandarinToLatin:(NSString *)string
{
    /*复制出一个可变的对象*/
    NSMutableString *preString = [string mutableCopy];
    /*转换成成带音 调的拼音*/
    CFStringTransform((CFMutableStringRef)preString, NULL, kCFStringTransformMandarinLatin, NO);
    /*去掉音调*/
    CFStringTransform((CFMutableStringRef)preString, NULL, kCFStringTransformStripDiacritics, NO);
    
    /*多音字处理*/
    if ([[(NSString *)string substringToIndex:1] compare:@"长"] == NSOrderedSame)
    {
        [preString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"chang"];
    }
    if ([[(NSString *)string substringToIndex:1] compare:@"沈"] == NSOrderedSame)
    {
        [preString replaceCharactersInRange:NSMakeRange(0, 4) withString:@"shen"];
    }
    if ([[(NSString *)string substringToIndex:1] compare:@"厦"] == NSOrderedSame)
    {
        [preString replaceCharactersInRange:NSMakeRange(0, 3) withString:@"xia"];
    }
    if ([[(NSString *)string substringToIndex:1] compare:@"地"] == NSOrderedSame)
    {
        [preString replaceCharactersInRange:NSMakeRange(0, 3) withString:@"di"];
    }
    if ([[(NSString *)string substringToIndex:1] compare:@"重"] == NSOrderedSame)
    {
        [preString replaceCharactersInRange:NSMakeRange(0, 5) withString:@"chong"];
    }
    
    NSMutableString *str = [NSMutableString stringWithString:preString];
    CFStringTransform((CFMutableStringRef) str, NULL, kCFStringTransformMandarinLatin, NO);
    CFStringTransform((CFMutableStringRef)str, NULL, kCFStringTransformStripDiacritics, NO);
    NSString *pinYin = [str capitalizedString];
    return [pinYin substringToIndex:1];
    
}



@end
